import 'package:flutter_admin/utils/utils.dart';
import 'package:quiver/strings.dart';

class PurchaseSupplierEvaluation {
  String? id;
  String? partnerId;
  String? buyerId;
  String? productId;
  String? templateId;
  String? templateName;
  String? comment;
  String? createUid;
  String? createDate;
  String? writeUid;
  String? writeDate;
  String? evaluationMonth;
  String? partnerCode;
  String? partnerName;
  String? productName;
  String? score;
  String? levelName;
  int? GJNR;
  int? GJSJ;
  int? JJCX;
  int? JQPJ;
  int? XYFW;
  int? ZLPJ;

  PurchaseSupplierEvaluation({
    this.id,
    this.partnerId,
    this.buyerId,
    this.productId,
    this.templateId,
    this.templateName,
    this.comment,
    this.createUid,
    this.createDate,
    this.writeUid,
    this.writeDate,
    this.evaluationMonth,
    this.partnerCode,
    this.partnerName,
    this.productName,
    this.score,
    this.levelName,
    this.GJNR,
    this.GJSJ,
    this.JJCX,
    this.JQPJ,
    this.XYFW,
    this.ZLPJ,
  });

  PurchaseSupplierEvaluation copyWith({
    String? id,
    String? partnerId,
    String? productId,
    String? templateId,
    String? comment,
    String? createUid,
    String? createDate,
    String? writeUid,
    String? writeDate,
    String? evaluationMonth,
  }) {
    return new PurchaseSupplierEvaluation(
      id: id ?? this.id,
      partnerId: partnerId ?? this.partnerId,
      productId: productId ?? this.productId,
      templateId: templateId ?? this.templateId,
      comment: comment ?? this.comment,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
      evaluationMonth: evaluationMonth ?? this.evaluationMonth,
    );
  }

  @override
  String toString() {
    return '''PurchaseSupplierEvaluation{
      id: $id,
      partnerId: $partnerId,
      productId: $productId,
      templateId: $templateId,
      comment: $comment,
      createUid: $createUid,
      createDate: $createDate,
      writeUid: $writeUid,
      writeDate: $writeDate,
      evaluationMonth: $evaluationMonth,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is PurchaseSupplierEvaluation &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          partnerId == other.partnerId &&
          productId == other.productId &&
          templateId == other.templateId &&
          comment == other.comment &&
          createUid == other.createUid &&
          createDate == other.createDate &&
          writeUid == other.writeUid &&
          writeDate == other.writeDate &&
          evaluationMonth == other.evaluationMonth);

  factory PurchaseSupplierEvaluation.fromMap(Map<String, dynamic> map) {
    return new PurchaseSupplierEvaluation(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      partnerId: map['partner_id']['id'] != false
          ? map['partner_id']['id'].toString() as String?
          : "",
      partnerCode: map['partner_id']['code'] != false
          ? map['partner_id']['code'].toString() as String?
          : "",
      partnerName: map['partner_id']['name'] != false
          ? map['partner_id']['name'].toString() as String?
          : "",
      productId: map['product_id'] != false
          ? map['product_id']['id'].toString() as String?
          : "",
      productName: map['product_id'] != false
          ? map['product_id']['name'].toString() as String?
          : "",
      templateId: map['template_id'][0] != false
          ? map['template_id'][0].toString() as String?
          : "",
      templateName: map['template_id'][1] != false
          ? map['template_id'][1].toString() as String?
          : "",
      comment:
          map['comment'] != false ? map['comment'].toString() as String? : "",
      createUid: map['create_uid'] != false
          ? map['create_uid'].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
      evaluationMonth: map['evaluation_month'] != false
          ? map['evaluation_month'].toString() as String?
          : "",
      score: map['score'] != false ? map['score'].toString() as String? : "",
      GJNR: map['GJNR'] != null ? map['GJNR'] : null,
      GJSJ: map['GJSJ'] != null ? map['GJSJ'] : null,
      JJCX: map['JJCX'] != null ? map['JJCX'] : null,
      JQPJ: map['JQPJ'] != null ? map['JQPJ'] : null,
      XYFW: map['XYFW'] != null ? map['XYFW'] : null,
      ZLPJ: map['ZLPJ'] != null ? map['ZLPJ'] : null,
    );
  }

  factory PurchaseSupplierEvaluation.fromMapanalysis(Map<String, dynamic> map) {
    return new PurchaseSupplierEvaluation(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      partnerId: map['partner_id'][0] != false
          ? map['partner_id'][0].toString() as String?
          : "",
      partnerCode: map['partner_id'][2] != false
          ? map['partner_id'][2].toString() as String?
          : "",
      partnerName: map['partner_id'][1] != false
          ? map['partner_id'][1].toString() as String?
          : "",
      productId: map['product_id'] != false
          ? map['product_id'][0].toString() as String?
          : "",
      productName: map['product_id'] != false
          ? map['product_id'][1].toString() as String?
          : "",
      templateId: map['template_id'] != false
          ? map['template_id'][0].toString() as String?
          : "",
      comment:
          map['comment'] != false ? map['comment'].toString() as String? : "",
      createUid: map['create_uid'] != false
          ? map['create_uid'].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
      evaluationMonth: map['evaluation_month'] != false
          ? map['evaluation_month'].toString() as String?
          : "",
      score: map['score'] != false ? map['score'].toString() as String? : "",
      levelName: map['level_name'] != false
          ? map['level_name'].toString() as String?
          : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'partnerId': this.partnerId,
      'productId': this.productId,
      'templateId': this.templateId,
      'comment': this.comment,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
      'evaluationMonth': this.evaluationMonth,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.partnerCode != null && this.partnerCode != '')
        ['partnercode', '=', '%${this.partnerCode}%'],
      if (this.partnerName != null && this.partnerName != '')
        ['partnername', '=', '%${this.partnerName}%'],
      if (this.evaluationMonth != null && this.evaluationMonth != '')
        ['start', '=', this.evaluationMonth],
      if (this.writeDate != null && this.writeDate != '')
        ['end', '=', this.writeDate],
      if (this.templateId != null && this.templateId != '')
        ['template_id', '=', int.parse(this.templateId!)]
    ];
    // ignore: unnecessary_cast
    return list;
  }

  List toanalysisList() {
    List list = [
      if (this.partnerId != null && this.partnerId != '')
        ['partnercode', 'like', '%${this.partnerId}%'],
      if (this.partnerName != null && this.partnerName != '')
        ['partnername', 'like', '%${this.partnerName}%'],
      if (this.evaluationMonth != null && this.evaluationMonth != '')
        ['start', '=', this.evaluationMonth],
      if (this.writeDate != null && this.writeDate != '')
        ['end', '=', this.writeDate],
      if (this.buyerId != null && this.buyerId != '')
        ['partner_id.buyer_id', '=', int.parse(this.buyerId!)],
      if (this.templateId != null && this.templateId != '')
        ['template_id', '=', int.parse(this.templateId!)]
    ];
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'partner_id':
          isNotBlank(this.partnerId) ? int.parse(this.partnerId!) : null,
      'product_id':
          isNotBlank(this.productId) ? int.parse(this.productId!) : null,
      'template_id':
          isNotBlank(this.templateId) ? int.parse(this.templateId!) : null,
      'comment': this.comment,
      'product_name': this.productName,
      // 'create_uid': this.createUid,
      // 'create_date': this.createDate,
      // 'write_uid': this.writeUid,
      // 'write_date': this.writeDate,
      'evaluation_month': this.evaluationMonth,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
